package com.example.master.mapper;

import com.example.master.dto.*;
import com.example.master.entity.*;
import org.apache.ibatis.annotations.*;

/**
 * @Author zcb
 * @PackageName a-great-masters
 * @Package com.example.master.mapper
 * @Date 2023/2/6 16:02
 * @Version 1.0
 */
@Mapper
public interface OrderMapper {

    //计算卖家成交的订单数
    @Select("select count(id) from tb_order where service_id=#{serviceId} and status=2")
    Integer countOrderNum(@Param("serviceId") Integer serviceId);

    @Select("select create_by from tb_service where id=#{ServiceId}")
    int sellerId(Integer serviceId);

    @Select("select nick_name from tb_user where id=#{sellerId}")
    String sellerNickName(Integer sellerId);

    @Select("select pay_type from tb_service where id=#{ServiceId}")
    Integer payType(Integer serviceId);


    @Select("select price from tb_service where id=#{ServiceId}")
    Long price(Integer serviceId);

    @Select("select service_img from tb_service where id=#{ServiceId}")
    String img(Integer serviceId);

    @Select("select g.game_name from tb_service s,tb_game g where s.game_id = g.id and s.id=#{ServiceId}")
    String getGameName(Integer serviceId);

    @Select("select price_remark from tb_service where id=#{ServiceId}")
    String priceRemark(Integer serviceId);

    @Select("SELECT s.price,o.create_by userId FROM tb_order o , tb_service s WHERE o.service_id = s.id AND o.order_no = #{orderNo}")
    OrderDTO getServiceByOrderNo(String orderNo);


    @Insert("INSERT into tb_order (order_no,price,type,`status`,create_time,create_by,modify_time,modify_by,service_id,seller_id) \n" +
            "VALUES (#{orderNo},#{price},#{type},#{status},#{createTime},#{createBy},#{modifyTime}, \n" +
            "#{modifyBy},#{serviceId},#{sellerId})")
    int insertOrder(Order order);

    @Insert("INSERT into tb_order_particulars (order_no,service_img,game_name,pay_type,price,price_remark,remark,create_time)\n" +
            "VALUES (#{orderNo},#{serviceImg},#{gameName},#{payType},#{price},#{priceRemark},#{remark},#{createTime})")
    int insertOrderParticulars(OrderParticulars orderParticulars);
}
